<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <button class="btn1">点我切换背景颜色</button>
    <!-- <div class="dad"> -->
    <!-- <button class="btn">开始点名</button> -->
    <!-- </div> -->
    <script>
        // 作业1：将字符串反转
        var str = "I Love You";
        var res = str.split("").reverse().join("");
        console.log(res);

        // 作业2.提取字符串参数
        var search = "?name=wangqi&age=22&height=180";

        function getparam(key, str) {
            var arr = str.slice(1, search.length).split("&")
            var obj = {}
            arr.forEach((v, index) => {
                var temp = v.split("=")
                obj[temp[0]] = temp[1]
            });
            return console.log(obj[key]);
        }
        getparam("height",search)
        // 作业3.点击按钮随机更换背景颜色

        var btn = document.querySelector(".btn1");

        function num(min, max) {
            return Math.round(Math.random() * (max + 1 - min) + min);
        }   
        btn.onclick = function () {
            document.body.style.backgroundColor = `rgb(${num(1,255)},${num(1,255)},${num(1,255)})`;
        }
    </script>
</body>

</html>